package view;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.geom.Line2D;
import java.util.ArrayList;

import javax.swing.ImageIcon;

import model.Ghost;

public class GhostGraphics implements Drawable{
	private Ghost ghost;
	private int stateIndex;
	private ArrayList<Image> images;	
	boolean debugModeOn;
	
	private static final int width = 50,height = 50;
	
	// constructor
	public GhostGraphics(String[] paths,Ghost ghost,boolean debugMode){
		this.ghost = ghost;
		stateIndex = 0;
		debugModeOn = debugMode;
		images = new ArrayList<Image>();
		loadImgs(paths);
	}
	
	// loads the 5 images for the ghost (up,down,left,right,dead)
	// the strings are assumed correct
	private void loadImgs(String[] imgPath){
		for (int i=0; i<5 ;i++){
			images.add(new ImageIcon(imgPath[i]).getImage());
		}
	}

	// for testing
	public void nextState(){
		stateIndex = (stateIndex+1)%5;
	}
	
	// changes the displayed images acording to the state
	public void changeState(int state){
			stateIndex = state;				
	}
	
	// draws the node 
	public void draw(Graphics g) {
		changeState(ghost.getDirection());
		g.drawImage(images.get(stateIndex),ghost.getX()-25,ghost.getY()-25,width,height,null);

		if(debugModeOn){
			Graphics2D g2 = (Graphics2D)g;
			g2.setStroke(new BasicStroke(3));
			g.setColor(new Color(255,0,0));

			g2.draw(new Line2D.Float(ghost.getX(),ghost.getY(),ghost.getX(),ghost.getY()));	
		}	
	}
}
